def call(build_Env ='') {

echo "=====================GENERATE VERSION WITH BUILD_ENV: ${build_Env}=================="  

if (env.GIT_COMMIT_ID != null) // 使用构建部署
  {
    if (build_Env == "N/A" ||build_Env == "")
    {
        VERSION_SUFFIX=""

    } else  {
        VERSION_SUFFIX="-${build_Env}"
    }

    if (env.gitlabActionType != null) // empty or null 判断job是否由 gitlab自动触发，该值只有在gitlab触发时才存在
    {
       // BRANCH = GIT_BRANCH.split('/')[1] 
       BRANCH= gitlabBranch // 如果是gitlab触发，则使用gitlab 环境变量
    }   
    else
    {
       BRANCH = BRANCH_TAG // 如果是手动触发, 使用手动选择的branch         
    }
        // ！！！！必须使用 env.VERSION_NUMBER . 不能使用 VERSION_NUMBER，否认不能作为全局变量被传递
    env.VERSION_NUMBER = VersionNumber([versionNumberString: '1.0.${BUILDS_ALL_TIME}'+"${VERSION_SUFFIX}"+"_${BRANCH}"+"_${env.GIT_COMMIT_ID}"]);

    currentBuild.displayName = "${env.VERSION_NUMBER}"
    currentBuild.description = "部署环境: ${params.DEPLOY_SERVER}\n执行人：${currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()}\n构建类型：CI&&CD"
  } else {
    env.VERSION_NUMBER = "${DEPLOY_VERSION}"

    currentBuild.displayName = VersionNumber projectStartDate: '', versionNumberString: '${DEPLOY_VERSION}_${BUILDS_TODAY}', versionPrefix: '', worstResultForIncrement: 'SUCCESS'
    currentBuild.description = "部署环境: ${params.DEPLOY_SERVER}\n执行人：${currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()}\n构建类型：CD"

  }
    echo "=====================GENERATE VERSION ${VERSION_NUMBER} DONE======================"
}